package com.yumijinfu.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import com.lzy.okhttputils.model.HttpParams;
import com.yumijinfu.R;
import com.yumijinfu.base.BaseActivity;
import com.yumijinfu.entity.Page;
import com.yumijinfu.http.HttpCallBack;
import com.yumijinfu.http.HttpUtils;
import com.yumijinfu.mian.Config;
import com.yumijinfu.response.RenChouDetailsRes;
import com.yumijinfu.tool.VibratorUtil;
import com.yumijinfu.view.ClearEditText;
import com.yumijinfu.view.TitleBar;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ekikousei易皇星 on 16/11/16.
 * E-mail:13764664731@163.com
 * Signature:缘分是本书,翻的不经意会错过,读的太认真会流泪!!
 * <p/>
 * TODO:类描述:  认筹详情
 */
public class RenChouDetailsActivity extends BaseActivity {
    @Bind(R.id.titlebar)
    TitleBar titlebar;
    @Bind(R.id.et_money_number_size)
    ClearEditText etMoneyNumberSize;
    @Bind(R.id.et_jiaoyi_password)
    ClearEditText etJiaoyiPassword;
    //
    private Page info;
    private String   borrowType;
    private  RenChouDetailsRes mRenChouDetailsRes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_renchou_details);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }
    @Override
    protected void initTitle() {
        info = (Page) getIntent().getSerializableExtra("info");
        if(null!=info){
            titlebar.setTitleBar(R.drawable.back_selector, info.getBorrowTitle(), 0);
        }

        titlebar.setTitleBarLeftListener(this);

    }

    @Override
    protected void initView() {


    }

    @Override
    protected void setData() {

        getData();
    }

    private void getData() {

        HttpParams params=new HttpParams();
        if(null!=info){
            params.put("borrowEId",info.getEid());
            HttpUtils.post(Config.SHOWBORROWRC, params, new HttpCallBack(this,"加载中...") {
                @Override
                public void onSucceed(JSONObject result, String code, String message) {


                    if(null!=result){
                        try {
                            mRenChouDetailsRes=new RenChouDetailsRes(new JSONObject(result.toString()));
                            if(null!=mRenChouDetailsRes){
                                borrowType=mRenChouDetailsRes.getBorrowType();


                            }



                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                }

                @Override
                public void onError(String code, String message) {

                    Toast.makeText(RenChouDetailsActivity.this,message, Toast.LENGTH_SHORT).show();
                }
            });
        }





    }

    @OnClick({R.id.tv_liji_touzi, R.id.lly_chick_details})
    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.titlebar_iv_back:

                finish();
                break;

            case R.id.tv_liji_touzi:     //立即投资
                long[] pattern = { 100, 400, 100, 400 };
                String mMoneyNumberSize = etMoneyNumberSize.getText().toString().trim();
                String mJiaoyiPassword = etJiaoyiPassword.getText().toString().trim();

                if (TextUtils.isEmpty(mMoneyNumberSize)) {
                    etMoneyNumberSize.setShakeAnimation();
                    VibratorUtil.Vibrate(RenChouDetailsActivity.this,pattern,false);
                    Toast.makeText(RenChouDetailsActivity.this, "认购金额数不能为空", Toast.LENGTH_SHORT).show();
                    return;

                }else if (TextUtils.isEmpty(mJiaoyiPassword)){
                    etJiaoyiPassword.setShakeAnimation();
                    VibratorUtil.Vibrate(RenChouDetailsActivity.this,pattern,false);
                    Toast.makeText(RenChouDetailsActivity.this, "交易密码不能为空", Toast.LENGTH_SHORT).show();
                    return;

                }

                break;

            case R.id.lly_chick_details:

                //RenChouXiangmuDetailsActivity
                Intent intent = new Intent(RenChouDetailsActivity.this,DetalInforDetailsActivity .class);
                if(null!=mRenChouDetailsRes){
                    intent.putExtra("mRenChouDetailsRes",mRenChouDetailsRes);
                    intent.putExtra("borrowType",borrowType);
                    startActivity(intent);
                }

//                finish();
                break;

            default:
        }
    }
}
